package com.empire.module.member.dal.mysql.transportationrecord;

import java.time.LocalDateTime;
import java.util.*;

import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.empire.framework.mybatis.core.mapper.BaseMapperX;
import com.empire.module.member.dal.dataobject.transportationrecord.TransportationRecordDO;
import org.apache.ibatis.annotations.Mapper;
import com.empire.module.member.controller.admin.transportationrecord.vo.*;

/**
 * 交通记录 Mapper
 *
 * @author 主席大人
 */
@Mapper
public interface TransportationRecordMapper extends BaseMapperX<TransportationRecordDO> {

    default PageResult<TransportationRecordDO> selectPage(TransportationRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TransportationRecordDO>()
                .betweenIfPresent(TransportationRecordDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(TransportationRecordDO::getPersonId, reqVO.getPersonId())
                .eqIfPresent(TransportationRecordDO::getTicketNumber, reqVO.getTicketNumber())
                .eqIfPresent(TransportationRecordDO::getType, reqVO.getType())
                .eqIfPresent(TransportationRecordDO::getStartLocation, reqVO.getStartLocation())
                .eqIfPresent(TransportationRecordDO::getEndLocation, reqVO.getEndLocation())
                .betweenIfPresent(TransportationRecordDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(TransportationRecordDO::getEndTime, reqVO.getEndTime())
                .eqIfPresent(TransportationRecordDO::getDuration, reqVO.getDuration())
                .eqIfPresent(TransportationRecordDO::getTransportationNumber, reqVO.getTransportationNumber())
                .eqIfPresent(TransportationRecordDO::getSource, reqVO.getSource())
                .likeIfPresent(TransportationRecordDO::getPassengerName, reqVO.getPassengerName())
                .eqIfPresent(TransportationRecordDO::getPassengerPhone, reqVO.getPassengerPhone())
                .eqIfPresent(TransportationRecordDO::getSeatNumber, reqVO.getSeatNumber())
                .eqIfPresent(TransportationRecordDO::getTotalPrice, reqVO.getTotalPrice())
                .eqIfPresent(TransportationRecordDO::getRemark, reqVO.getRemark())
                .eqIfPresent(TransportationRecordDO::getReadStatus, reqVO.getReadStatus())
                .betweenIfPresent(TransportationRecordDO::getBusstarttime, reqVO.getBusstarttime())
                .betweenIfPresent(TransportationRecordDO::getOperationtime, reqVO.getOperationtime())
                .eqIfPresent(TransportationRecordDO::getCarno, reqVO.getCarno())
                .betweenIfPresent(TransportationRecordDO::getCheckintime, reqVO.getCheckintime())
                .orderByDesc(TransportationRecordDO::getId));
    }

    default List<TransportationRecordDO> selectPresentationList(Set<Long> personIdList, LocalDateTime startTime, LocalDateTime endTime) {
        return selectList(new LambdaQueryWrapperX<TransportationRecordDO>()
                .in(TransportationRecordDO::getPersonId, personIdList)
                .and(i -> i
                        .between(TransportationRecordDO::getStartTime, startTime, endTime)
                        .or()
                        .between(TransportationRecordDO::getEndTime, startTime, endTime)
                ).orderByDesc(TransportationRecordDO::getCreateTime)
                .last(" limit 1000"));
    }

}